// JavaScript Document

function bindEvent(obj, sEv, fn) {
	if (obj.addEventListener) {
		obj.addEventListener(sEv, fn, false);
	} else {
		obj.attachEvent('on'+sEv, function() {
			fn.call(obj);
		});
	}
}	
function fn1(jData){
	var data=jData.s;
	var oT=document.getElementById('text');
	var oUl=document.getElementById('result');
	var aLi=oUl.getElementsByTagName('li');
	oUl.innerHTML = '';
	if(data.length){
		oUl.style.display="block";
		for(var i=0;i<data.length;i++){
			var oLi=document.createElement('li');
			oLi.innerHTML=data[i];
			oUl.appendChild(oLi);
			oLi._href=data[i];
			oLi.onclick=function(ev){
				var ev=ev||event;
				ev.cancelBubble=true;
				window.open('http://www.baidu.com/s?wd='+this._href+'&rsv_bp=0&ch=&tn=baidu&bar=&rsv_spt=3&ie=utf-8&rsv_sug3=5&rsv_sug=0&rsv_sug1=5&rsv_sug4=807&oq=s&rsp=0&f=3&rsv_sug2=1&rsv_sug5=0&inputT=2205480');
			};
		}
		
		for(var j=0;j<aLi.length;j++){
			aLi[j].onmouseover=function(){
				for(var i=0;i<aLi.length;i++){
					aLi[i].style.background="#fff";	
				}
				this.style.background="#ccc";
			}
		}
	}else{
		oUl.style.display='none';
	}
}
function startMove(obj,json,endFn){
	
	clearInterval(obj.timer);
	
	obj.timer = setInterval(function(){
		
		var bBtn = true;
		
		for(var attr in json){
			
			var iCur = 0;
		
			if(attr == 'opacity'){
				if(Math.round(parseFloat(getStyle(obj,attr))*100)==0){
				iCur = Math.round(parseFloat(getStyle(obj,attr))*100);
				
				}
				else{
					iCur = Math.round(parseFloat(getStyle(obj,attr))*100) || 100;
				}	
			}
			else{
				iCur = parseInt(getStyle(obj,attr)) || 0;
			}
			
			var iSpeed = (json[attr] - iCur)/8;
		iSpeed = iSpeed >0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
			if(iCur!=json[attr]){
				bBtn = false;
			}
			
			if(attr == 'opacity'){
				obj.style.filter = 'alpha(opacity=' +(iCur + iSpeed)+ ')';
				obj.style.opacity = (iCur + iSpeed)/100;
				
			}
			else{
				obj.style[attr] = iCur + iSpeed + 'px';
			}
			
			
		}
		
		if(bBtn){
			clearInterval(obj.timer);
			
			if(endFn){
				endFn.call(obj);
			}
		}
		
	},30);

}


function getStyle(obj,attr){
	if(obj.currentStyle){
		return obj.currentStyle[attr];
	}
	else{
		return getComputedStyle(obj,false)[attr];
	}
}

function stopMove(obj){
	clearInterval(obj.timer);
}

function getByClass(sClass,parent){
		
	var aEles=(parent||document).getElementsByTagName('*');
	var arr=[];
	
	for(var i=0;i<aEles.length;i++){
	
		aClass=aEles[i].className.split(' ');// aEles里面存的是例如li，ul等等节点。
		for(var j=0;j<aClass.length;j++){
		
			if(aClass[j]==sClass){
			
				arr.push(aEles[i]);// 存在数组中的类型是对象；
			}
		}
	}
	

	return arr;
}

function removeClass(obj,sClass){
	var aClass=[];
	if(!obj.className){
		return;
	}
	aClass=obj.className.split(' ')
	for(var j=0;j<aClass.length;j++){
	
		if(aClass[j]==sClass){				
			aClass.splice(j,1)
			obj.className=aClass.join(' ');
			return;
		}
		
	}
}


function addClass(obj,sClass){
	
	if(!obj.className){
			obj.className=sClass;
			return;
	}
		
	aClass=obj.className.split('');
	for(var j=0;j<aClass.length;j++){
		
		if(aClass[j]==sClass){
			return;
		}
	}
	obj.className +=' '+sClass;
}
		
		
function setCookie(key, value, t) {
	var oDate = new Date();
	oDate.setDate(oDate.getDate() + t);
	document.cookie = key + '=' + encodeURI(value) + ';expires=' + oDate.toUTCString();
}
function getCookie(key) {
	var arr = document.cookie.split('; ');
	for (var i=0; i<arr.length; i++) {
		var arr2 = arr[i].split('=');
		if (arr2[0] == key) {
			return decodeURI(arr2[1]);
		}
	}
}
function delCookie(key) {
	setCookie(key, '', -1);
}

function viewW(){
	return document.documentElement.clientWidth;	
}

function viewH(){
	return document.documentElement.clientHeight;
}

function scrollX(){

	return 	document.body.scrollLeft || document.documentElement.scrollLeft;
	
}

function scrollY(){

	return 	document.body.scrollTop || document.documentElement.scrollTop;

}

function scrollH(){
	return document.body.scrollHeight;	
}
function first(parent){
	return parent.firstElementChild||parent.firstChild;
}
function last(parent){
	return parent.lastElementChild||parent.lastChild;
}
function next(obj){
	return obj.nextElementSibling||obj.nextSibling;
}

function prev(obj){
	return obj.previousElementSibling || obj.previousSibling;
}